package net.bwie.realtime.jtp.function;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.flink.api.common.functions.RichFilterFunction;
import org.apache.flink.configuration.Configuration;

import java.util.HashSet;
import java.util.Set;



/**
 * 简介说明:
 *
 * @author: LiLi
 * @date: 2025/06/02 16:40:47
 * @version: 1.0
 */
public class DimDataFilterFunction extends RichFilterFunction<String> {

    private final Set<String> dimSet;


    //   todo: 数据操作类型
    private final Set<String> operateTypeSet = new HashSet<String>() {{
        add("insert");
        add("update");
        add("delete");
    }};

    public DimDataFilterFunction(Set<String> dimSet) {
        this.dimSet = dimSet;
    }

    @Override
    public void open(Configuration parameters) throws Exception {
        super.open(parameters);
    }

    @Override
    public boolean filter(String value) throws Exception {

        JSONObject jsonObject = JSON.parseObject(value);

        String tableName = jsonObject.getString("table_name");

        String operatorType = jsonObject.getString("operate_type");

        return dimSet.contains(tableName) && operateTypeSet.contains(operatorType);
    }

    @Override
    public void close() throws Exception {
        super.close();
    }
}
